package com.demo2do.fms.admin.entity.search.data;

import java.util.List;
import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 * 修理费查询
 * 
 * @author Wy
 *
 */
public class RepairFeeSearch implements QueryBuilder {
    
    /** 公司 */
    private List<Long> organizationIds;
    
    /** 所选的动力类型 */
    private Long powerTypeId;
    
    /** 公里数范围的上限 */
    private Integer rangeFrom;
    
    /** 公里数范围的下限 */
    private Integer rangeTo;
    
    private QueryOrder order;
    
    private QueryFilter filter;
    
    /**
     * default construction
     */
    public RepairFeeSearch(){
        order = new QueryOrder("organization.name", "ASC")
                          .add("createDate", "DESC");
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
      public QueryFilter getPreparedFilter(boolean refresh) {
        
        if(filter == null || refresh) {
            
            filter = new QueryFilter().addEquals("vehicleFeature.id", powerTypeId)
                                      .addGreaterThanEqual("rangeFrom", rangeFrom)
                                      .addLessThanEqual("rangeTo", rangeTo)
                                      .addSentence("organization.id IN (:organizationIds)", "organizationIds", organizationIds);
        }
         return filter;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return order;
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM RepairFee WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
      
    /**
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }
    
    /**
     * 
     * @return organizationIds
     */
    public List<Long> getOrganizationIds() {
        return organizationIds;
    }
    
    /**
     * 
     * @return powerTypeId
     */
    public Long getPowerTypeId() {
        return powerTypeId;
    }

    /**
     * 
     * @return rangeTo
     */
    public Integer getRangeTo() {
        return rangeTo;
    }

    /**
     * 
     * @return rangeFrom
     */
    public Integer getRangeFrom() {
        return rangeFrom;
    }
    
    /**
     * 
     * @param organizationIds the organizationIds to set
     */
    public void setOrganizationIds(List<Long> organizationIds) {
        this.organizationIds = organizationIds;
    }

    /**
     * 
     * @param powerTypeId to set powerTypeId
     */
    public void setPowerTypeId(Long powerTypeId) {
        this.powerTypeId = powerTypeId;
    }

    /**
     * 
     * @param rangeTo to set rangeTo
     */
    public void setRangeTo(Integer rangeTo) {
        this.rangeTo = rangeTo;
    }

    /**
     * 
     * @param rangeFrom to set rangeFrom
     */
    public void setRangeFrom(Integer rangeFrom) {
        this.rangeFrom = rangeFrom;
    }
      
    


}
